// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

/*==================================================
  Cookie functions
  ==================================================*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function categoryToggle (catName) {
  catStatus = getCookie("expanded_cat_" + catName);
  if (catStatus == "true") {
    setCookie("expanded_cat_" + catName, false);
    $("expand_"+catName).update("+");
    Effect.BlindUp(catName,{duration:0.2});
  }
  else
  {
    setCookie("expanded_cat_" + catName, true);
    $("expand_"+catName).update("-");
    Effect.BlindDown(catName,{duration:0.2});
  }  
} 

function categoryExpandAll (catArray) {
  for (var i in catArray) {
    setCookie("expanded_cat_" + catArray[i], true);
    Effect.BlindDown(catArray[i],{duration:0.2});
    $("expand_" + catArray[i]).update("-");
  }
} 

function categoryContractAll (catArray) {
  for (var i in catArray) {
    setCookie("expanded_cat_" + catArray[i], false);
    Effect.BlindUp(catArray[i],{duration:0.2});
    $("expand_" + catArray[i]).update("+");
  }
} 